package com.tmc.util;

import java.util.HashMap;
import java.util.Map;

import com.tmc.entity.intair.CommisionPolicy;
public class PolicyUtil {

	public static String getTrueOrFalse(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("是") || type.contains("True")) {
			return "True";	
		}
		if (type.contains("否") || type.contains("False")) {
			return "False";
		}
		if (type.contains("不限") || type.contains("UnLimited")) {
			return "UnLimited";
		}
		return type;
	}

	public static String getTrueOrFalseName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("是") || type.contains("True")) {
			return "是";
		}
		if (type.contains("否") || type.contains("False")) {
			return "否";
		}
		if (type.contains("不限") || type.contains("UnLimited")) {
			return "不限";
		}
		return type;
	}

	public static String getCommisionCalculation(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("取严") || type.contains("TakeStrict")) {
			return "TakeStrict";
		}
		if (type.contains("各取各") || type.contains("TakeSelf")) {
			return "TakeSelf";
		}
		return type;
	}

	public static String getCommisionCalculationName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("取严") || type.contains("TakeStrict")) {
			return "取严";
		}
		if (type.contains("各取各") || type.contains("TakeSelf")) {
			return "各取各";
		}
		return type;
	}

	// 旅客资质 普通成人Adult 留学生AbroadStudent,劳工Labor,Immigrant移民,Sailor海员
	public static String getEligibility(String eligibility) {
		if (ObjectUtil.noText(eligibility)) {
			return "Adult/AbroadStudent/Labor/Immigrant/Sailor";
		}
		eligibility = eligibility.trim();
		StringBuffer sb = new StringBuffer();
		if (eligibility.contains("成人") || eligibility.contains("Adult")) {
			sb.append("Adult/");
		}
		if (eligibility.contains("留学生") || eligibility.contains("AbroadStudent")) {
			sb.append("AbroadStudent/");
		}
		if (eligibility.contains("劳工") || eligibility.contains("Labor")) {
			sb.append("Labor/");
		}
		if (eligibility.contains("移民") || eligibility.contains("Immigrant")) {
			sb.append("Immigrant/");
		}
		if (eligibility.contains("海员") || eligibility.contains("Sailor")) {
			sb.append("Sailor/");
		}
		return sb.substring(0, sb.length() - 1);
	}

	// 旅客资质 普通成人Adult 留学生AbroadStudent,劳工Labor,Immigrant移民,Sailor海员
	public static String getEligibilityName(String eligibility) {
		if (ObjectUtil.noText(eligibility)) {
			return "成人/留学生/劳工/移民/海员";
		}
		eligibility = eligibility.trim();
		StringBuffer sb = new StringBuffer();
		if (eligibility.contains("成人") || eligibility.contains("Adult")) {
			sb.append("成人/");
		}
		if (eligibility.contains("留学生") || eligibility.contains("AbroadStudent")) {
			sb.append("留学生/");
		}
		if (eligibility.contains("劳工") || eligibility.contains("Labor")) {
			sb.append("劳工/");
		}
		if (eligibility.contains("移民") || eligibility.contains("Immigrant")) {
			sb.append("移民/");
		}
		if (eligibility.contains("海员") || eligibility.contains("Sailor")) {
			sb.append("海员/");
		}
		return sb.substring(0, sb.length() - 1);
	}

	// 乘客类型 Adult,Child,Infant
	public static String getPassengerType(String passengerType) {
		if (ObjectUtil.noText(passengerType)) {
			return "Adult/Child/Infant";
		}
		passengerType = passengerType.trim();
		StringBuffer sb = new StringBuffer();
		if (passengerType.contains("成人") || passengerType.contains("Adult")) {
			sb.append("Adult/");
		}
		if (passengerType.contains("儿童") || passengerType.contains("Child")) {
			sb.append("Child/");
		}
		if (passengerType.contains("婴儿") || passengerType.contains("Infant")) {
			sb.append("Infant/");
		}
		return sb.substring(0, sb.length() - 1);
	}

	// 乘客类型 Adult,Child,Infant
	public static String getPassengerTypeName(String passengerType) {
		if (ObjectUtil.noText(passengerType)) {
			return "成人/儿童/婴儿";
		}
		passengerType = passengerType.trim();
		StringBuffer sb = new StringBuffer();
		if (passengerType.contains("成人") || passengerType.contains("Adult")) {
			sb.append("成人/");
		}
		if (passengerType.contains("儿童") || passengerType.contains("Child")) {
			sb.append("儿童/");
		}
		if (passengerType.contains("婴儿") || passengerType.contains("Infant")) {
			sb.append("婴儿/");
		}
		return sb.substring(0, sb.length() - 1);
	}

	public static String getInvoiceType(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("行程单") || type.contains("Itinerary")) {
			return "Itinerary";
		}
		if (type.contains("旅游发票") || type.contains("TravelInvoice")) {
			return "TravelInvoice";
		}
		return type;
	}

	public static String getInvoiceTypeName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("行程单") || type.contains("Itinerary")) {
			return "行程单";
		}
		if (type.contains("旅游发票") || type.contains("TravelInvoice")) {
			return "旅游发票";
		}
		return type;
	}

	public static String getFlightType(String flightType) {
		if (ObjectUtil.noText(flightType) || (flightType.contains("单程") && flightType.contains("往返"))) {
			return "OW/RT";
		}
		flightType = flightType.trim();
		if (flightType.contains("单程") || flightType.contains("OW")) {
			return "OW";
		}
		if (flightType.contains("往返") || flightType.contains("RT")) {
			return "RT";
		}
		return flightType;
	}

	public static String getFlightTypeName(String flightType) {
		if (ObjectUtil.noText(flightType) || (flightType.contains("OW") && flightType.contains("RT"))) {
			return "单程/往返";
		}
		flightType = flightType.trim();
		if (flightType.contains("单程") || flightType.contains("OW")) {
			return "单程";
		}
		if (flightType.contains("往返") || flightType.contains("RT")) {
			return "往返";
		}
		return flightType;
	}

	public static String getProductType(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("包机切位") || type.contains("1")) {
			return "1";
		}
		if (type.contains("申请") || type.contains("2")) {
			return "2";
		}
		if (type.contains("直销") || type.contains("3")) {
			return "3";
		}
		if (type.contains("清仓产品") || type.contains("4")) {
			return "4";
		}
		if (type.contains("特惠") || type.contains("5")) {
			return "5";
		}
		return type;
	}

	public static String getProductTypeName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("包机切位") || type.contains("1")) {
			return "包机切位";
		}
		if (type.contains("申请") || type.contains("2")) {
			return "申请";
		}
		if (type.contains("直销") || type.contains("3")) {
			return "直销";
		}
		if (type.contains("清仓产品") || type.contains("4")) {
			return "清仓产品";
		}
		if (type.contains("特惠") || type.contains("5")) {
			return "特惠";
		}
		return type;
	}

	public static String getIsAirport(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("城市") || type.contains("False")) {
			return "False";
		}
		if (type.contains("机场") || type.contains("True")) {
			return "True";
		}
		return type;
	}

	public static String getIsAirportName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("城市") || type.contains("False")) {
			return "城市";
		}
		if (type.contains("机场") || type.contains("True")) {
			return "机场";
		}
		return type;
	}

	public static String getOpenJawType(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("双缺") || type.contains("1")) {
			return "1";
		}
		if (type.contains("单缺") || type.contains("2")) {
			return "2";
		}
		if (type.contains("始发缺") || type.contains("3")) {
			return "3";
		}
		if (type.contains("目的地缺") || type.contains("4")) {
			return "4";
		}
		return type;
	}

	public static String getOpenJawTypeName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("双缺") || type.contains("1")) {
			return "双缺";
		}
		if (type.contains("单缺") || type.contains("2")) {
			return "单缺";
		}
		if (type.contains("始发缺") || type.contains("3")) {
			return "始发缺";
		}
		if (type.contains("目的地缺") || type.contains("4")) {
			return "目的地缺";
		}
		return type;
	}

	public static String getIndicator(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("第一国际段") || type.contains("FirstSegment")) {
			return "FirstSegment";
		}
		if (type.contains("始发航段") || type.contains("InitialSegment")) {
			return "InitialSegment";
		}
		if (type.contains("主航段") || type.contains("MainSegment")) {
			return "MainSegment";
		}
		return type;
	}

	public static String getIndicatorName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("第一国际段") || type.contains("FirstSegment")) {
			return "第一国际段";
		}
		if (type.contains("始发航段") || type.contains("InitialSegment")) {
			return "始发航段";
		}
		if (type.contains("主航段") || type.contains("MainSegment")) {
			return "主航段";
		}
		return type;
	}

	public static String getTicketType(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("BSP")) {
			return "BSP";
		}
		if (type.contains("航空公司") || type.contains("Airline")) {
			return "Airline";
		}
		return type;
	}

	public static String getTicketTypeName(String type) {
		if (type == null || "".equals(type)) {
			return type;
		}
		type = type.trim();
		if (type.contains("BSP")) {
			return "BSP电子票";
		}
		if (type.contains("航空公司") || type.contains("Airline")) {
			return "航空公司本票电子客票";
		}
		return type;
	}
	
	/**
	 * 以下是政策显示的一些方法
	 * */
	
	
//	if(ObjectUtil.hasText(policy.getChild())){
//		policy.setChildStr("");
//		if(policy.getChild().equals("1")){
//			policy.setChildStr("奖励与成人一致");
//		}
//		if(policy.getChild().equals("2")){
//			policy.setChildStr("儿童可开无奖励");
//		}
//		if(policy.getChild().equals("3")){
//			policy.setChildStr("儿童不可开");
//		}
//		if(policy.getChild().equals("4")){
//			policy.setChildStr("儿童指定奖励"+(policy.getChdReward())+"%");
//		}		
//	}
	
	public static String getTicketTypeStr(String type){
		if(ObjectUtil.hasText(type)){
			StringBuilder str = new StringBuilder();
			if(type.contains("BSP")){
				str.append("BSP,");
			}
			if(type.contains("B2B")){
				str.append("B2B,");
			}
			if(type.contains("overseas")){
				str.append("境外电子,");
			}
			return str.toString().substring(0, str.length()-1);

		}
		return "";	
	}
	
	public static String getChildStr(CommisionPolicy policy){
		if(ObjectUtil.hasText(policy.getChild())){
			StringBuilder str = new StringBuilder();
			policy.setChildStr("");
			if(policy.getChild().equals("1")){
				str.append("奖励与成人一致");
			}
			if(policy.getChild().equals("2")){
				str.append("儿童可开无奖励");
			}
			if(policy.getChild().equals("3")){
				str.append("儿童不可开");
			}
			if(policy.getChild().equals("4")){
				str.append("儿童指定奖励"+(policy.getChdReward()==null? 0:policy.getChdReward())+"%");
			}		
			return str.toString();
		}
		return "";	
	}
	
	public static String getChildExtStr(CommisionPolicy policy){
		if(ObjectUtil.hasText(policy.getChildExt())){
			String[] strings = policy.getChildExt().split(",");
			StringBuilder str = new StringBuilder();
			for (String string : strings) {
				if(string.equals("1")){
					str.append("儿童加收手续费"+(policy.getChdServicePrice() == null ? 0D : policy.getChdServicePrice())+"元  ");
				}else if(string.equals("2")){
					str.append("儿童无代理费  ");
				}else if(string.equals("3")){
					str.append("儿童不单开  ");
				}else if(string.equals("4")){
					str.append("儿童不直减  ");
				}
			}
			return str.toString();
		}
		
		return "";
	}
	
	public static String getInfantStr(String type){
		if(ObjectUtil.hasText(type)){
			StringBuilder str = new StringBuilder();
			if(type.equals("1")){
				str.append("婴儿可开无奖励");
			}
			if(type.equals("2")){
				str.append("婴儿不可开");
			}
			return str.toString();
		}
		return "";
		
	}
	
	public static String getInfantExtStr(CommisionPolicy policy){
		String str="";
		if(ObjectUtil.hasText(policy.getInfantExt())){
			str="婴儿加收手续费"+(policy.getInfServicePrice() == null ? 0D : policy.getInfServicePrice())+"元  ";
		}
		return str;
	}
	
	public static String getEligibilityExcludeStr(String type){
		if(ObjectUtil.hasText(type)){
			StringBuilder str = new StringBuilder();
			Map<String,String> map = new HashMap<String,String>();
			map.put("A", "留学生");map.put("B", "移民");
			map.put("C", "劳工");map.put("D", "海员");
			map.put("E", "青年");map.put("R", "老年");
			map.put("F", "探亲");map.put("T", "港澳台");
			map.put("M", "外籍");map.put("U", "非汉字姓名");
			map.put("V", "Add-On");map.put("W", "境外中转");
			map.put("N", "OPPEN");map.put("P", "SPA");
			map.put("H", "三方协议");map.put("I", "套票");
			map.put("J", "整团");map.put("K", "小团");
			String[]  strings = type.split(",");
			for (String string : strings) {
				str.append(map.get(string)+",");
			}
			return str.toString();
		}
		return "";
	}
	public static String getTravelerCountsExtStr(String type){
		if(ObjectUtil.hasText(type)){
			StringBuilder str = new StringBuilder();
			if(type.contains("1")){
				str.append("仅双人");
			}
			if(type.contains("2")){
				str.append("同退改");
			}
			return str.toString();
		}
		return "";
	}
	
	public static String getCombinationStr(CommisionPolicy policy){
		StringBuilder str = new StringBuilder();
		if(ObjectUtil.hasText(policy.getCombination())){		
			str.append("允许混舱1/2RT ");			
		}
		if(ObjectUtil.hasText(policy.getCombinationExt())){
			if(policy.getCombinationExt().contains("1")){
				str.append(policy.getCombinationStr()+"运价基础需一致   ");
			}
			if(policy.getCombinationExt().contains("2")){
				str.append(policy.getCombinationStr()+"票面略低");
			}
		}
		return str.toString();
	}
}
